package learningThread.threadPool;

import java.util.concurrent.*;

/**
 * newCachedThreadPool 根据需要创建新线程的线程池
 *
 * 参数核心线程池corePoolSize = 自定义, maximumPoolSize = Integer.MAX_VALUE，
 * 这也就是说当任务被提交到线程池时，
 *
 *
 */
public class TestNewSheduledThreadExcutorPool {

    public static void main(String[] args) {
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);

        ThreadPoolExecutor scheduledExecutorService1 = (ThreadPoolExecutor) scheduledExecutorService;

        scheduledExecutorService.scheduleWithFixedDelay(new Runnable() {
            @Override
            public void run() {
                System.out.println("当前线程核心线程数:" + scheduledExecutorService1.getCorePoolSize()
                        + "最大线程数:" + scheduledExecutorService1.getMaximumPoolSize()
                        + "线程存活时间:" + scheduledExecutorService1.getKeepAliveTime(TimeUnit.MILLISECONDS)
                        + "已完成的线程数:" + scheduledExecutorService1.getCompletedTaskCount()
                        + "存活的线程数为:" + scheduledExecutorService1.getActiveCount());
                System.out.println("当前线程池数量:" + scheduledExecutorService1.getPoolSize());
            }
        },1000,3000,TimeUnit.MILLISECONDS);

    }
}
